<!-- 批量修改单价的dialog -->
<template>
    <div class=''>
        <el-form ref="form" :model="form" label-width="60px" class="custom-form" :rules="rules">
            <el-form-item label="单价" class="flex">
                <el-input-number v-model="form.price" controls-position="right" :min="0"
                    :controls="false"></el-input-number>
                <div class="unit">元</div>
            </el-form-item>


            <div class="btn-box">
                <el-button type="primary" @click="editPrice">保存</el-button>
            </div>
        </el-form>
    </div>
</template>

<script>
import { editPrice } from '@/api/moneyManagment';
export default {
    //import引入的组件需要注入到对象中才能使用
    components: {},
    props: ['form'],
    data() {
        //这里存放数据
        return {
            rules: {

            }
        };
    },
    //监听属性 类似于data概念
    computed: {},
    //监控data中的数据变化
    watch: {},
    //方法集合
    methods: {
        async editPrice() {
            if (this.form.price <= 0) {
                this.$message.error('请输入正确的单价!')
                return;
            };
            let res = await editPrice(this.form);
            if (res.code == 200) {
                this.$message.success(res.msg)
            } else {
                this.$message.error(res.msg)
            }

            this.$emit('closeDialog')
        }
    },
    //生命周期 - 创建完成（可以访问当前this实例）
    created() {

    },
    //生命周期 - 挂载完成（可以访问DOM元素）
    mounted() {

    },
    beforeCreate() { }, //生命周期 - 创建之前
    beforeMount() { }, //生命周期 - 挂载之前
    beforeUpdate() { }, //生命周期 - 更新之前
    updated() { }, //生命周期 - 更新之后
    beforeDestroy() { }, //生命周期 - 销毁之前
    destroyed() { }, //生命周期 - 销毁完成
    activated() { }, //如果页面有keep-alive缓存功能，这个函数会触发
}
</script>
<style lang='scss' scoped>
//@import url(); 引入公共css类
::v-deep .custom-form {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-evenly;
    margin: 40px 20%;

    .flex {
        .el-form-item__content {
            display: flex;
        }
    }

    .unit {
        height: 40px;
        padding: 0 20px;
        transform: scaleX(1.02);
        background-color: #f5f7fa;
        color: #999;
        border: 1px solid #DCDFE6;
        border-top-right-radius: 5px;
        border-bottom-right-radius: 5px;
    }


    .el-input-number {
        width: 100%;

        // .el-input-number__decrease {
        //     display: none;
        // }

        // .el-input-number__increase {
        //     display: none;
        // }

        .el-input__inner {
            text-align: left;
            padding-right: 30px;
        }
    }


    .btn-box {
        width: 100%;
        display: flex;
        justify-content: center;
        flex-direction: column;
        align-items: center;

        .el-button {
            width: 100px;
        }
    }
}
</style>